package net.slowpoison.loveclock.client;


public class Ticker {
	private static int DOT_DIA = 16;
	private static int SEP = 2;
	private static int STRCOUNT = 4;
	private static int DIGITS_PER_STRING = 3;
	
	private String[] dStrs; //= new String[] { "999", "99", "99", "99" };
	private Digit[][] digits = new Digit[STRCOUNT][DIGITS_PER_STRING];
	private Colon[] colons = new Colon[STRCOUNT - 1];
	
	public Ticker(String timeStr, int x, int y) {
		int n = 0;
		dStrs = timeStr.split(":");
		
		// create the digits arrays 
		for (int i=0; i < STRCOUNT; ++i) {
			Dot.DotType dottype = Dot.DotType.values()[i+1];
			for (int j=0; j < dStrs[i].length(); ++j) {
				digits[i][j] = new Digit(dottype, dStrs[i].charAt(j) - 48,
						x + n *(Digit.getWidth() + 4*SEP) + i*(Colon.getWidth() + 2*SEP),
						y);
				++n;
//				Log.v("dot", "digit " + digits[i][j].getX() + ", " + digits[i][j].getY());
			}
			if (i < STRCOUNT - 1)
				colons[i] = new Colon(x + n*(Digit.getWidth() + 4*SEP) + i*(Colon.getWidth() + SEP),
								y + ((Digit.getHeight() - Colon.getHeight())/2));
		}
	}
	
	public void set(String timeStr) {
		dStrs = timeStr.split(":");
		
		for (int i=0; i < STRCOUNT; ++i) {
			for (int j=0; j < dStrs[i].length(); ++j) {
				digits[i][j].set(dStrs[i].charAt(j) - 48);
			}
		}
	}

	public static int getWidth() {
		return (9 * (Digit.getWidth() + 4*SEP) - SEP) + 
			((STRCOUNT - 1) * (Colon.getWidth() + 2*SEP) - SEP);
	}
	
	public static int getHeight() {
		return Digit.getHeight();
	}

	public static int getDia() {
		return DOT_DIA;
	}
	
	public static int getSep() {
		return SEP;
	}
}